# 导包
from api.login import LoginAPI
import config
from common.assertutil import common_assert
import pytest
from common.jsonutil import build_data

# 创建测试接口类
class TestLoginAPI:
    # 设置属性
    uuid = None

    # 前置处理
    def setup(self):
        # 实例化接口对象
        self.login_api = LoginAPI()
        # 获取图片验证码
        res_v = self.login_api.get_verify_code()
        # 获取响应数据中的uuid值
        TestLoginAPI.uuid = res_v.json().get("uuid")

    # 后置处理
    def teardown(self):
        pass

    # 登录成功
    @pytest.mark.parametrize("username, password, status_code, message, code", build_data(config.BASE_PATH + "/data/login.json"))
    def test01_login(self, username, password, status_code, message, code):
        # 登录
        login_data = {
            "username": username,
            "password": password,
            "code": "2",
            "uuid": TestLoginAPI.uuid
        }
        res_l = self.login_api.login(login_data)
        common_assert(res_l,status_code, message, code)



